package com.orkasgb.framework.hadoop.mapperreduce.hbase;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class HBaseMapper {

    public static void main(String[] args) throws JsonProcessingException {
        String str = "{\"CODE\":\"01\",\"KEY\":\"HUAWEI\",\"NAME\": [\"HUAWEI\",\"华为\"]}";
//        String concat = StringUtils.replace(StringUtils.split(StringUtils.split(str, ",")[1], ":")[1], "\"" ,"");
//        System.out.println(concat);

        // System.out.println(String.valueOf(JSONObject.parseObject(concat, Map.class).get("KEY")));

        ObjectMapper objectMapper = new ObjectMapper();
        Map map = objectMapper.readValue(str, Map.class);

        Map map1 = JSONObject.parseObject(str, Map.class);


        Demo demo = new Demo();
        demo.setName(str);

        ArrayList<Demo> list = new ArrayList<Demo>();
        list.add(demo);

        List<Demo> collect = list.stream().filter(demo1 -> StringUtils.isNoneBlank(demo1.getName()))
                .peek(demo1 -> {
                    String name = StringUtils.substringBetween(demo1.getName(), ",", ",");
                    String name1 = StringUtils.replace(StringUtils.substringAfter(name, ":"), "\"", "");
                    demo1.setName(name1);
                })
                .collect(Collectors.toList());

        System.out.println(collect);
    }
}

class Demo {
    String name;

    public Demo() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Demo{" +
                "name='" + name + '\'' +
                '}';
    }
}
